// Copyright 2011 Google Inc. All Rights Reserved.

package com.google.fbyoutube.client.widget;

import com.google.gwt.user.client.Element;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Image;

/**
 * @author xiaodao@google.com (Xiao Dao Wu)
 *
 */
public class CustomButton extends Button {

  private String text;

  public CustomButton(){
      super();
  }

  public void setResource(ImageResource imageResource){
      Image img = new Image(imageResource);
      String definedStyles = img.getElement().getAttribute("style");
      img.getElement().setAttribute("style", definedStyles + "; vertical-align:middle;");
      DOM.insertBefore(getElement(), img.getElement(), DOM.getFirstChild(getElement()));
  }

  @Override
  public void setText(String text) {
      this.text = text;
      Element span = DOM.createElement("span");
      span.setInnerText(text);
      span.setAttribute("style", "padding-left:3px; vertical-align:middle;");

      DOM.insertChild(getElement(), span, 0);
  }

  @Override
  public String getText() {
      return this.text;
  }
}
